package com.repast.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.repast.common.ServerResponse;
import com.repast.pojo.DeskTime;
import com.repast.service.IDeskService;
import com.repast.service.IDeskTimeService;
import com.repast.utils.DateUtils;

@Controller
@RequestMapping("/desk/")
public class DeskController {

	@Autowired
	private IDeskService deskService;
	@Autowired
	private IDeskTimeService deskTimeService;

	// 查询所有的桌子
	@RequestMapping("list.do")
	@ResponseBody
	public ServerResponse selectDeskList() {
		return deskService.selectDeskList();
	}

	// 0表示成功,1001表示已经被预约了
	// 根据id查询当前桌子是否被预定
	@RequestMapping("no_user.do")
	@ResponseBody
	public ServerResponse selectNoUserDesk(Integer deskId,
			@RequestParam(value = "appointCreateTime", defaultValue = "-1") String appointCreateTime) throws Exception {
		Date date;
		if (appointCreateTime.equals("-1")) {
			date = new Date();
		}else{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			date = sdf.parse(appointCreateTime);
		}
		return deskTimeService.selectDeskTimeById(deskId, date);
	}
}
